package com.sunday.common.mq.kafka.study.spring.e12_Serialization_Deserialization_Message_Conversion_Type;

import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.springframework.kafka.support.serializer.DelegatingSerializer;

import java.util.Map;

public class MyProducerInterceptor implements ProducerInterceptor<Object, Object> {


    @Override
    public void configure(Map<String, ?> configs) {

    }

    @Override
    public ProducerRecord<Object, Object> onSend(ProducerRecord<Object, Object> record) {
        record.headers().add(DelegatingSerializer.VALUE_SERIALIZATION_SELECTOR, record.value().getClass().getName().getBytes());
        return record;
    }

    @Override
    public void onAcknowledgement(RecordMetadata metadata, Exception exception) {
    }

    @Override
    public void close() {
    }

}

